/*
 * Corte.java
 *
 * Created on April 19, 2008, 4:02 PM
 */

package GUI;

import AccesoDatos.ConMySQL;
import AccesoDatos.Dato;
import AccesoDatos.Vista;
import ReglasNegocio.Finca;
import ReglasNegocio.ProduccionDiaria;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.swingx.autocomplete.*;

/**
 *
 * @author  developer
 */
public class frmProduccionDiaria extends javax.swing.JFrame {
    
    /** Creates new form Corte */
    public frmProduccionDiaria() {
        initComponents();
        this.cmbFinca.setModel(this.modeloFincas());
        this.comboFincaVer.setModel(this.modeloFincas());
        AutoCompleteDecorator.decorate(comboFincaVer);
        AutoCompleteDecorator.decorate(cmbFinca);
        this.tablaPD.setModel(this.modeloPP());
    }
    private DefaultComboBoxModel modeloFincas() {
        DefaultComboBoxModel modelo=new DefaultComboBoxModel();
        String buscar="select * from finca";
        ConMySQL con=new ConMySQL();
        con.Conectar();
        Vista v=con.crearVista(buscar);
        if (v.getNRegistros()>0) {
            for(int i=0;i<v.getNRegistros();i++) {
                long id=(Long)v.getRegistro(i, 0);
                Dato idFinca=new Dato("id",String.valueOf(id));
                Finca f=new Finca(idFinca);
                modelo.addElement(f);
            }
        }
        
        return modelo;
    }
    
    public DefaultTableModel modeloPP() {
        DefaultTableModel modelo=new DefaultTableModel();
        
        modelo.addColumn("Id");
        modelo.addColumn("qq Repesa");
        modelo.addColumn("qq Entregados");
        modelo.addColumn("qq Planilla");
        modelo.addColumn("Fecha");
        
        Finca f=(Finca)this.comboFincaVer.getSelectedItem();
        String sql="select * from producciondiaria where fkfinca='"+f.getId()+"'";
        ConMySQL con=new ConMySQL();
        con.Conectar();
        Vista v=con.crearVista(sql);
        if(v.getNRegistros()>0) {
            for(int i=0;i<v.getNRegistros();i++) {
                long idPd=(Long)v.getRegistro(i, 0);
                Dato id=new Dato("id",String.valueOf(idPd));                
                ProduccionDiaria pd=new ProduccionDiaria(id);
                String[] fila={pd.getIdentificador().getValor(),String.valueOf(pd.getQuintalesRepesa()),String.valueOf(pd.getQuintalesEntregadosBeneficio()),String.valueOf(pd.getQuintalesPlanilla()),pd.getFecha().toString()};
                modelo.addRow(fila);
            }
        }
        return modelo;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        comboFincaVer = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaPD = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cmbFinca = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtRepesa = new javax.swing.JTextField();
        txtBeneficio = new javax.swing.JTextField();
        txtPlanilla = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel5.setFont(new java.awt.Font("Dialog", 0, 24));
        jLabel5.setText("Control de Corte Diario"); // NOI18N

        jLabel7.setText("Finca"); // NOI18N

        comboFincaVer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboFincaVerActionPerformed(evt);
            }
        });

        tablaPD.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane2.setViewportView(tablaPD);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(136, 136, 136)
                        .addComponent(jLabel5))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18)
                        .addComponent(comboFincaVer, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addGap(23, 23, 23)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(comboFincaVer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 468, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Modificar", jPanel2);

        jLabel1.setFont(new java.awt.Font("Dialog", 0, 24));
        jLabel1.setText("Control de Corte Diario"); // NOI18N

        jLabel2.setText("Finca"); // NOI18N

        cmbFinca.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Himalaya", "Kilimanharu", "Los naranjos", "Galicia" }));

        jButton1.setText("Guardar"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel3.setText("Quintales Beneficio");

        jLabel4.setText("Quintales Planilla");

        jLabel6.setText("Quintales Repesa");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton1))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(62, 62, 62)
                            .addComponent(jLabel1))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(24, 24, 24)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2)
                                .addComponent(jLabel3)
                                .addComponent(jLabel4)
                                .addComponent(jLabel6))
                            .addGap(31, 31, 31)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtRepesa, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                                .addComponent(txtPlanilla, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                                .addComponent(cmbFinca, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtBeneficio, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)))))
                .addContainerGap(231, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jLabel1)
                .addGap(37, 37, 37)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cmbFinca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtRepesa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtBeneficio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(txtPlanilla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addComponent(jButton1)
                .addContainerGap(281, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Registrar", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 570, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(21, Short.MAX_VALUE)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 611, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
private DefaultTableModel modeloProduccion(){
  
    DefaultTableModel modelo= new DefaultTableModel();
    modelo.addColumn("Fecha");
    modelo.addColumn("Identificador");
    modelo.addColumn("qq Planilla");
    modelo.addColumn("qq Beneficio");
    modelo.addColumn("qq Respesa");
    
    Finca f=(Finca)this.cmbFinca.getSelectedItem();
    
    String consulta="select * from producciondiaria where fkfinca='"+f.getIdentificador().getValor()+"'";
        ConMySQL con=new ConMySQL();
        con.Conectar();
        
        Vista v=con.crearVista(consulta);
        
        if (v.getNRegistros()>0) {
            for(int i=0;i<v.getNRegistros();i++) {
                long id=(Long)v.getRegistro(i, 0);
                Dato idProduccion=new Dato("id",String.valueOf(id));
              ProduccionDiaria fa=new ProduccionDiaria(idProduccion);
                //String[] fila={fa.get.getValor(),fa.getNombre(),fa.getDireccion(),String.valueOf(fa.getManzanas()),fa.getMandador().getNombres()};
                //modelo.addRow(fila);
            }
        }
    
    return modelo;
    
    
}

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    
        ProduccionDiaria pro= new ProduccionDiaria();
        
        pro.setFinca((Finca)this.cmbFinca.getSelectedItem());
        pro.setQuintalesRepesa(Double.valueOf(this.txtRepesa.getText()));
        pro.setQuintalesEntregadosBeneficio(Double.valueOf(this.txtBeneficio.getText()));
        pro.setQuintalesPlanilla(Double.valueOf(this.txtPlanilla.getText()));
        pro.Crear();
        
        this.txtBeneficio.setText("");
        this.txtPlanilla.setText("");
        this.txtRepesa.setText("");
        this.tablaPD.setModel(this.modeloPP());
        JOptionPane.showMessageDialog(this, "Se ha registrado una produccion ");
               
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

private void comboFincaVerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFincaVerActionPerformed
// TODO add your handling code here:
    this.tablaPD.setModel(this.modeloPP());
}//GEN-LAST:event_comboFincaVerActionPerformed
    
    public static void main(String[] args) {
        new frmProduccionDiaria().setVisible(true);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbFinca;
    private javax.swing.JComboBox comboFincaVer;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable tablaPD;
    private javax.swing.JTextField txtBeneficio;
    private javax.swing.JTextField txtPlanilla;
    private javax.swing.JTextField txtRepesa;
    // End of variables declaration//GEN-END:variables
    
}
